<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8" />
    <title>Vue中操作数组</title>
    <!-- 引入Vue -->
    <script type="text/javascript" src="../../js/vue.js"></script>
  </head>
  <body>
    <!-- 准备好一个容器-->
    <div id="demo">
      <ul>
        <li v-for="p in persons" :key="p.id">{{p.name}}-{{p.age}}-{{p.gender}}</li>
      </ul>
      <button @click="change1">修改马冬琪的名字</button>
      <button @click="change2">修改马冬琪的年龄</button>
      <button @click="change3">修改马冬琪的性别</button>
      <button @click="change4">修改马冬琪</button>
    </div>

    <script type="text/javascript">
      const vm = new Vue({
        el:'#demo',
        data:{
          persons:[
            {id:'gyastrdt1',name:'马冬琪',age:18,gender:'女'},
            {id:'gyastrdt2',name:'周冬雨',age:19,gender:'女'},
            {id:'gyastrdt3',name:'周杰伦',age:20,gender:'男'},
            {id:'gyastrdt4',name:'温兆伦',age:21,gender:'男'}
          ]
        },
        methods: {
          change1(){
            this.persons[0].name = '李夏天' 
          },
          change2(){
            this.persons[0].age = 99 
          },
          change3(){
            this.persons[0].gender = '男' 
          },
          change4(){
            this.persons.splice(0,1,{id:'gyastrdt1',name:'tony',age:66,gender:'未知'})

            // Vue2中永远不要通过下标操作元素，要用那7个变更方法
            // this.persons[0] = {id:'gyastrdt1',name:'tony',age:66,gender:'未知'}

            // console.log(this.persons.splice === Array.prototype.splice)
          }
        },
      })
      console.log(vm)
    </script>
  </body>
</html>